package top.zy.page.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.zy.page.service.PageService;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 9:19 2019/7/9
 */
@Component
public class ListenerMessage {

    @Autowired
    private PageService pageService;

    /***
     *
     * @param spuId
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "zymall.create.page.queue",durable = "true"),exchange = @Exchange(value = "zymall.goods.exchange",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),key = {"goods.insert","goods.update"}))
         public void listenerCreateAndUpdateIndex(Long spuId){
            if (spuId==null){
                return;
            }
            //创建静态化页面
            pageService.createHtml(spuId);
        }

    /****
     *
     * @param spuId
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "zymall.delete.page.queue",durable = "true"),exchange = @Exchange(value = "zymall.goods.exchange",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),key = "goods.delete"))
    public void listenerDeleteIndex(Long spuId){
        if (spuId==null){
            return;
        }
        //删除静态化页面
        pageService.deleteHtml(spuId);
    }
}
